package com.atguigu.distributed.lock.service;

import com.atguigu.distributed.lock.mapper.StockMapper;
import com.atguigu.distributed.lock.pojo.Stock;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author BLADE
 * @description:
 * @data 2024/4/2410:34
 */
@Service
public class StockService {
    @Autowired
    private StockMapper stockMapper;

    public void deduct(){

        try{
            Stock stock = this.stockMapper.selectOne(new QueryWrapper<Stock>().eq("product_code", "1001"));
            if(stock!=null && stock.getCount()>0){
                stock.setCount(stock.getCount()-1);
                this.stockMapper.updateById(stock);
            }
        }finally {
        }
    }

}
